package com.zhiyou.controller;

import com.zhiyou.entity.PowerCenter;
import com.zhiyou.util.DBUtil;
import com.zhiyou.util.PWUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author sanshi
 * @desc
 * @create 2021-09-03 15:45
 */
@WebServlet("/DoAlterServlet")
public class DoAlterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        Object[] params = {password,username};
        String sql = "update sys_user set pwd = ? where acct = ? ";
        DBUtil util = new DBUtil();
        int i = util.updateInfo(sql, params);
        if (i==0){
            resp.sendRedirect("accountError.jsp");
        }else{
            //修改成功
//            ArrayList<User> list = util.getAllUser();
//            session.setAttribute("list",list);
            List<PowerCenter> pcList = new PWUtil().getAllPC3();
            session.setAttribute("pcList",pcList);
            session.setAttribute("alter","success");
            resp.sendRedirect("/page/AccountManagement.jsp");
        }

    }
}
